home *** CD-ROM | disk | FTP | other *** search
- #include <ConsLaw.h>
- #include <DrawFD.h> // defines makeCurvPlot (FieldFD&,...)
- real start1 (const Ptv(real)& x, real t) { return 0.0; }
- real linearFlux (real u) { return u; }
-
- void ConsLaw:: init ()
- {
- f = linearFlux;
-
- grid.rebind (new GridLattice(1)); grid->scan (s_i);
- u.rebind (new FieldFD (grid(), "u"));
- u_prev.rebind (new FieldFD (grid(), "u_prev"));
- u_prev() = start1;
- const real uL = 1; u->valueIndex(0) = u_prev->valueIndex(0) = uL;
- tip.scan (s_i);
- file.open (CaseName);
- time_points_for_plot.scan (s_i);
-
- // write input data for a check:
- u->grid().print(s_o); tip.print(s_o);
- s_o << "time points for plot: "; time_points_for_plot.print (s_o);
- }
-
- void ConsLaw:: solveProblem ()
- {
- init ();
-
- // abbreviations:
- # define Un(i) u->valueIndex(i)
- # define Un_1(i) u_prev->valueIndex(i)
- # define Fn_1(i) f(u_prev->valueIndex(i))
-
- real mu = tip.Delta()/u->grid().Delta(1);
- const int n0 = u->grid().getBase(1); // first grid point
- const int n1 = u->grid().getMaxI(1); // last grid point
- int i;
- tip.initTimeLoop();
- while (!tip.finished()) {
- tip.increaseTime();
- for (i = n0+1; i <= n1; i++) {
- Un(i) = Un_1(i) - mu * (Fn_1(i) - Fn_1(i-1)); }
- if (time_points_for_plot.within (tip.getTime(), 0.4999*tip.Delta()))
- DrawFD::makeCurvPlot (u(),file,"u(x) for t fixed","u",
- oform("t=%g",tip.getTime()));
- u_prev() = u();
- }
- # undef Un
- # undef Un_1
- # undef Fn_1
- }
-
-